(* ::Package:: *)

BeginPackage["LocationEstimator`", "JLink`"]

LocationEstimator::usage = "My Package"
EstimateLocation::usage = "returns the location of the reporting tag"

Begin["LocationEstimator`"]

ShowJavaConsole[];

EstimateLocation[data_] := (source = {0, 0}; 
     fit = NonlinearModelFit[data, Norm[{x, y} - {x0, y0}], {x0, y0}, {x, y}, 
       Weights -> 1/data[[All,3]]^2]; (*ellipsoid = 
      fit["ParameterConfidenceRegion", ConfidenceLevel -> 0.95]; *)
     solution = fit["ParameterConfidenceIntervalTableEntries"][[All,1]]; 
     (*Graphics[{Opacity[0.2], EdgeForm[Opacity[0.75]], White, 
       (Disk[Most[#1], Last[#1]] & ) /@ data, Opacity[1], Red, ellipsoid, 
       PointSize[0.0125], Blue, Point[source], Red, Point[solution], 
       PointSize[0.0083], White, (Point[Most[#1]] & ) /@ data}, 
      Background -> Black, ImageSize -> 600];*) Return[solution]; )
End[]

EndPackage[]



